package com.travel.server.manager.impl.command.article;

import com.travel.common.CommonConstant;
import com.travel.server.manager.dto.request.article.DeleteArticleClassRequest;
import com.travel.server.manager.dto.response.EmptyResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.ArticleClassDal;
import com.travel.server.manager.model.ArticleClassInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/20 16:19
 * @Desc:
 */
@Component
public class DeleteArticleClassCommand extends AbstractCommand<DeleteArticleClassRequest, EmptyResponse> {

    @Autowired
    private ArticleClassDal classDal;

    @Override
    protected void checkInput(DeleteArticleClassRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public EmptyResponse handle(DeleteArticleClassRequest request) {
        checkInput(request);

        ArticleClassInfo info = classDal.selectById(request.getId());
        info.setUpdateTime(new Date());
        info.setUpdateBy(getUserInfo().getName());
        info.setState(CommonConstant.NO);

        classDal.insertOrUpdate(info);
        return new EmptyResponse();
    }
}
